package com.example.gateway.configuration;

import com.example.gateway.filter.MyRedisRateLimiter;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.cloud.gateway.support.ConfigurationService;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.ReactiveStringRedisTemplate;
import org.springframework.data.redis.core.script.RedisScript;

import java.util.List;

/**
 * @author DestinyCc
 * @date 2022/5/8
 */
@Configuration
public class MyRedisRateLimiterConfiguration {

    @Bean
    public MyRedisRateLimiter myRedisRateLimiter(ReactiveStringRedisTemplate redisTemplate,
                                               @Qualifier(MyRedisRateLimiter.REDIS_SCRIPT_NAME) RedisScript<List<Long>> redisScript,
                                               ConfigurationService configurationService) {
        return new MyRedisRateLimiter(redisTemplate, redisScript, configurationService);
    }
}
